from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dwd.tab.dwd_tab_barscan_loading_base_hi import jms_dwd__dwd_tab_barscan_loading_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi

#
jms_hi_dm__dm_tms_sitesend_number_ht = SparkSqlOperator(
    task_id='jms_hi_dm__dm_tms_sitesend_number_ht',
    task_concurrency=1,
    pool_slots=4,
    master='yarn',
    execution_timeout=timedelta(hours=3),
    email= ['macheng@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_hi_dm__dm_tms_sitesend_number_ht_{{ execution_date | cst_ds }}',
    sql='jms_hi/dm/dm_tms_sitesend_number_ht/execute.sql',
    driver_memory='6G',
    #executor_memory='12G',
    executor_memory='4G',
    driver_cores=4,
    #executor_cores=10,
    executor_cores=5,
    #num_executors=10,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    num_executors=3,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors'             : 4,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 200,
          'spark.default.paralleism': 200,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.executor.memoryOverhead': '4G',  # 堆外内
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
)


jms_hi_dm__dm_tms_sitesend_number_ht << [
    jms_dwd__dwd_tab_barscan_loading_base_hi,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
]
